<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('收款计划列表')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>项目：</label>
                                <select name="projectId" id="projectId" class="form-control m-b" th:with="type=${@customDictService.selectDictNotStaffingProject()}" required>
                                    <option value="">请选择</option>
                                    <option th:each="dict : ${type}" th:text="${dict.title}" th:value="${dict.id}"></option>
                                </select>
                            </li>
                            <li>
                                <label>计划类型：</label>
                                <select name="planType">
                                    <option value="">所有</option>
                                    <option value="staffing">外派</option>
                                    <option value="other">项目</option>
                                </select>
                            </li>
                            <li>
                                <label>成本中心：</label>
                                <select name="businessUnitDepartmentId" th:with="type=${@customDictService.selectDictBusinessUnitWithDepartments()}">
                                    <option value="">请选择</option>
                                    <optgroup th:each="unit: ${type}" th:label="${unit.name}">
                                        <option th:each="department : ${unit.departments}" th:text="${department.name}" th:value="${department.id}"></option>
                                    </optgroup>
                                </select>
                            </li>
                            <li>
                                <label>金额：</label>
                                <input type="text" name="expectAmount" placeholder="计划收款金额"/>
                            </li>
                            <li class="select-time">
                                <label>计划时间：</label>
                                <input type="text" class="time-input" placeholder="开始时间" name="params[beginTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" placeholder="结算时间" name="params[endTime]"/>
                            </li>

                            <li>
                                <label>计划状态：</label>
                                <select name="params[planStatus]" th:with="type=${@dict.getType('receivable_status_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>认证类型：</label>
                                <select name="cognizanceType" th:with="type=${@dict.getType('cognizance_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="erp:receivable:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="erp:receivable:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: select2-js" />
     <th:block th:include="include :: bootstrap-select-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('erp:receivable:edit')}]];
        var removeFlag = [[${@permission.hasPermi('erp:receivable:remove')}]];
        var planNumberDatas = [[${@dict.getType('account_number')}]];
        var planStatusDatas = [[${@dict.getType('receivable_status_type')}]];
        var cognizanceTypeDatas = [[${@dict.getType('cognizance_type')}]];
        var invoiceStatusDatas = [[${@dict.getType('sys_yes_no')}]];
        var prefix = ctx + "erp/receivable";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                onClickCell: onClickCell,
                modalName: "收款计划",
                sortName: "id",
                sortOrder: "desc",
                columns: [
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'customerName',
                    title: '客户'
                },
                {
                    field: 'title',
                    title: '项目/结算'
                },
                {
                    field: 'businessUnitName',
                    title: '事业部'
                },
                {
                    field: 'planNumber',
                    title: '收款笔数',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(planNumberDatas, value);
                    }
                },
                {
                    field: 'expectAmount',
                    title: '计划收款金额'
                },
                {
                    field: 'payedAmount',
                    title: '已收款金额',
                    cellStyle: function (value, row, index){
                        if (value != 0) {
                            return {
                                css: {color: "blue",cursor: "pointer"}
                            }
                        }else
                        {
                            return {}
                        }

                    }
                },
                {
                    field: 'planReceiveDate',
                    title: '计划收款时间'
                },
                {
                    field: 'latestReceiveDate',
                    title: '上次收款时间'
                },
                {
                    field: 'planStatus',
                    title: '计划状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(planStatusDatas, value);
                    }
                },
                {
                    field: 'cognizanceType',
                    title: '认证类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(cognizanceTypeDatas, value);
                    }
                },
                {
                    field: 'cognizanceDate',
                    title: '认定时间'
                },
                {
                    field: 'invoiceStatus',
                    title: '已开发票',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(invoiceStatusDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        var addDetailUrl = prefix + "/detail/add/other/" + row.id;
                        var addDetailTitle = row.title +  " 新增收款";
                        if (row.planType == 'staffing') {
                            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="$.modal.open(\'' + addDetailTitle + '\',\'' + addDetailUrl + '\',1120)"><i class="fa fa-dollar"></i>收款</a> ');
                        }else{
                            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="$.modal.open(\'' + addDetailTitle + '\',\'' + addDetailUrl + '\')"><i class="fa fa-dollar"></i>收款</a> ');
                        }

                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        if (row.planType != 'staffing'){
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }

                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function onClickCell(field, value, row, $element){
            if (field == 'payedAmount' && value != 0){
                var tittle = row.title  + '第' + $.table.selectDictLabel(planNumberDatas, row.planNumber) + '笔收款记录' ;
                var detailUrl = prefix + "/detail/" + row.id + "/detail";
                $.modal.openTab(tittle,detailUrl);
            }
        }
    </script>
</body>
</html>